package com.shop.www.service.Impl;


import com.shop.www.dao.CommodityDAO;
import com.shop.www.model.Commodity;
import com.shop.www.model.Order;
import com.shop.www.model.User;
import com.shop.www.service.Commodityservice;
import com.shop.www.service.Orderservice;
import com.shop.www.service.Userservice;

import java.util.List;

public class CommodityserviceImpl implements Commodityservice {
    private CommodityDAO commodityDAO;
    private Userservice userservice;
    private Orderservice orderservice;
    @Override
    public List getcommodityList(String key) {//获取所有上架商品的详细信息，包括商家
        List<Commodity> list = commodityDAO.getcommodity(key,1);
        for(Commodity commodity :list){
            User saler = userservice.getuserByID(commodity.getUser_ID());
            commodity.setSaller(saler);
        }
        return list;
    }

    @Override
    public Commodity getcommodityByID(Integer Commodity_ID) {//获取单个商品的详细信息，包括商家
        Commodity commodity =  commodityDAO.getcommodityByID(Commodity_ID);
        User saler = userservice.getuserByID(commodity.getUser_ID());
        commodity.setSaller(saler);
        return commodity;

    }

    @Override
    public List getsellerList() {//获取全部商家的信息
        List<User> list = userservice.getseller();
        return list;
    }

    @Override
    public List getcommodityListbyseller(Integer user_ID,String state) {//根据ID获取对应商家的全部商品
        List<Commodity> list = commodityDAO.getcommodityListbyseller(user_ID,state);
        //根据商家查找全部待出货订单
        return list;
    }


    @Override
    public void updatecommoditystate(Commodity commodity) {
       commodityDAO.updatecommoditystate(commodity);
    }

    @Override
    public void addcommodity(Commodity commodity) {
        commodityDAO.addcommodity(commodity);
    }

    @Override
    public void sellcommodity(Commodity commodity) {
        commodityDAO.sellcommodity(commodity);
    }

    @Override
    public void updatecommodity(Commodity commodity) {
        commodityDAO.updatecommodity(commodity);
    }

    @Override
    public void delcommodity(Integer Commodity_ID) {
        commodityDAO.delcommodity(Commodity_ID);
    }


}
